home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / PROGRAMMING / TORNADO / GBPB < prev    next >
Text File  |  1995-05-25  |  9KB  |  150 lines

  1. A few tips for writing fully multitasking applications (which incidentally is
  2. part of the Tornado application standard, from which this excerpt is taken):
  3.  
  4. ...
  5.  
  6. Guideline 5b:
  7.    The execution of the application, from the time the user double-clicks on
  8. the filer icon to the time the application calls OS_Exit, must never halt the
  9. Wimp for more than half a second unless so desired by the user, which has to
  10. be indicated through a configuration file stored on a non-volatile media,
  11. which can be altered and reset through the usual methods (editor, preferences
  12. window). As usual, this half-second applies to applications running in Mode
  13. 0, RISC-OS 2 and on an Arm2 processor (no FPA).
  14.  
  15. Elaboration:
  16.    Use SWI Tornado_StartPreemption to preempt areas of code which would
  17. otherwise be difficult to poll continously. Note that this approach to
  18. writing code should be on a 'have-to' basis, as using this method places an
  19. unnecessary burden on the processor, and also deprives the user of the use of
  20. the application, as Wimp_Poll reason codes are not acted upon. It is usually
  21. not only easy, but desirable to work on a system of multithreading the
  22. polling process so that full application usage & functionality may be
  23. retained during processing. Although it is possible & acceptable for the task
  24. to allow multiple internal processes to proceed at once, this is not
  25. necessary and one multithreaded process can be done at once, but returning to
  26. the previous process when the first has finished. If you must have multiple
  27. processes occuring at once (which can be difficult and buggy to code), write
  28. them into seperate hotlinked applications (for the time being, this is up to
  29. you, but support for this may eventually come from the module). The method
  30. used by C of multiple processes occuring within the one task is acknowledged
  31. & appreciated, but it is stressed that our approach of putting these
  32. processes into entirely seperate tasks is both easier, and less hassle to
  33. approach. Also, a very big plus is it allows asyndrochous processing,
  34. something we feel important as it is by no means inevitable multiple
  35. processer microcomputer architectures will not emerge in the near future, and
  36. in the possible future the Tornado master option window may allow subtasks to
  37. be sent to a remote processor and executed there, pending return. If you wish
  38. to adopt this approach, ask the Tornado group for a (currently alpha) copy of
  39. the subtask commuinication protocol.
  40.  
  41.    For filing system use (loading, saving, searching media based files), we
  42. suggest you use the SWI "Tornado_MultitaskLoad" and SWI
  43. "Tornado_MultitaskSave". These are easy to use, but disable your application
  44. during use, and the hourglass should be shown indicating the application is
  45. now offline. Unfortunately, you can't simply call Tornado_StartPreemption
  46. followed with an OS_File, as OS_File runs in SVC and preemption is disabled
  47. at this time. You must do it another way.
  48.      You can multithread the i/o routine with polling, like this:
  49.   "Tornado_StartLoadN",task handle,ptr to file,address of buffer,blk length
  50. TO R0 (R0=handle, if zero the file couldn't be opened)
  51.   .startloop
  52.   Branch to general purpose polling routine, nothing disabled
  53.   "Tornado_LoadIntN",handle TO handle (if the handle ever becomes zero, an
  54. error has occurred, -1 then the file is loaded)
  55.   Test if handle =-1 or =0, if true remove ptr and exit; if false, update ptr
  56. and branch to .startloop.
  57.     ... or you can use SWI "Tornado_StartLoadI" and SWI "Tornado_StartSaveI",
  58. like this:
  59. <To start:>"Tornado_StartLoadI",task handle,ptr to file,address of
  60. buffer,time interval TO R0 (R0=handle, if zero the file couldn't be opened)
  61. <Regularly after:> "Tornado_LoadIntI",handle TO handle (if the handle ever
  62. becomes zero, an error has occurred, -1 then the file is loaded). Test if
  63. handle =-1 or =0, if true the i/o is finished; if false, update ptr and do
  64. whatever you were doing before
  65.    The difference is that ***I SWI's will keep on working even when the
  66. desktop is halted eg; the user is using a non-desktop program, has hit f12,
  67. etc. etc. The ***N SWI's don't actually multitask, it's the branch to the
  68. polling routine that does that. The SWI "Tornado_LoadIntN" simply loads in a
  69. section of the file at a time, a section small enough not to take more than
  70. half a second. This is the preferred method, and should be used unless you
  71. have a very good reason not to.
  72.    The ***I SWI's, on the otherhand, operate above all USR mode code: on the
  73. same level as the higher-level i/o routines, like the serial port - they will
  74. keep on performing the i/o even when you might be playing a game, on the comm
  75. line etc. etc. They use interrupts to load in the blocks, but while a task is
  76. suspended it will have no control over the i/o. For this reason, it is
  77. recommended that you write a section of module code to perform the i/o
  78. control; note that the module does NOT need to poll the Wimp - these calls do
  79. not even need the Wimp to function. Essentially, if you can write the i/o
  80. routine without needing some module code, write it using ***N. It's better
  81. all round.
  82.    A situation which would need the ***I set would be where an application is
  83. reading in vital data from a device and saving it to disc. Whereas before,
  84. the data would be i/o from a section of memory, now it can be done direct to
  85. disc. If the device absolutely needs a constant flow of data, then this
  86. method is ideal - the module code handles the i/o between the memory buffer
  87. and the device, and the ***I does the media i/o. This way, the device is
  88. never left wanting for data.
  89.   Note that this implies that the buffer space into which the i/o is being
  90. performed must reside in non-multipaged memory, such as that in the RMA &
  91. memory areas under RISC-OS 3.5+. This does NOT include application space, and
  92. pointing the routine into there will almost cause undefined results. Note
  93. also that these calls also add a huge amount of latency to the system, and
  94. can disrupt much of the i/o system also running under standard interrupts
  95. (eg; the serial port) and occasionally lower system functions like the mouse
  96. pointer. However, this only affects standard IRQ code, and shouldn't touch
  97. the lower still FIQ which handles very low system functions. Please also note
  98. that overloading the interrupt system is unwise, and can cause many problems
  99. for tasks in USR mode relying on system responsiveness, which is why the ***I
  100. calls will only allow two threads running simultanously. Do not expect your
  101. request to be guaranteed serviced.
  102.  
  103.    In !Run files, modules should be loaded using *MultitaskRMLoad which loads
  104. in modules without halting the Wimp, which is done by starting up a module
  105. Wimp task which performs the loading of blocks into memory in between polls.
  106. !RunImage should be run using *MultitaskRun, also doing the i/o by the
  107. aforementioned method. Also, during the main part of the !Run file, the
  108. hourglass should be used, and setting the LED's appropriate to what task is
  109. in progress. The top LED should be on during input i/o (loading, reading in),
  110. bottom on during output i/o (saving, writing out), both on during
  111. non-multitasking processing, and both off during multitasking processing. A
  112. percentage should also be displayed if possible/appropriate.
  113.    However, better still if it can utilise the Tornado timeto feature which
  114. shows the estimated time to completion under the mouse pointer. This is
  115. done using the *Hourglass command, and by right you should also set the
  116. pointer to whether you are multitasking or not. See the call definition for
  117. further details. This is also available via SWI "Tornado_Hourglass".
  118.    Also, if your !Run file is so long as to breach the half second limit,
  119. move bits around ie; a *MultitaskRMLoad can be placed into the middle of a
  120. section of (say) *Set's which is too long - this allows the Wimp to be
  121. polled, and polling continued.
  122.  
  123.    Finally, remember that you must implement the Tornado per-application
  124. standard, allowing the Tornado module to display local application options
  125. within the application's option window. This will allow the user to set
  126. options, applicable to every Tornado task, which relate to this specific area
  127. of constant multi-tasking (ie; for this task constant multitasking is
  128. on/off). It is also hoped that programmers adopting this standard will extend
  129. the standard Tornado options to include application specific suboptions,
  130. allowing say only sprite mapping to hog all of the machine's processing
  131. power and all others full multitasking.
  132.  
  133. ...
  134.  
  135. Tornado command details:
  136. ----------------------------------------------------------------------------
  137. SWI
  138.  
  139. ...
  140.  
  141. End of excerpt.
  142.  
  143. Anyway, I know it's a bit detailed and gives info on a whole bunch of as yet
  144. useless commands, but I think you'll all find it interesting.
  145.  
  146. Give me any feedback you wish (is crap, is good etc.). My addresses are in
  147. the ReadMe file.
  148.  
  149. nd
  150.